package com.tenglong.teacher.ui.homepage;

import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.gson.Gson;
import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.AnswerInfo;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

public class TestActivity extends AppCompatActivity {

    private RecyclerView mRecy;
    private List<AnswerInfo> infos;
    private MyAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        getData();
        initView();
    }

    private void getData() {
        infos = new ArrayList<>();
        for (int i = 0 ; i <20 ; i ++){
            infos.add(new AnswerInfo());
        }
    }

    private void initView() {
        mRecy = findViewById(R.id.mRecy);
        GridLayoutManager manan = new GridLayoutManager(this, 2);
        manan.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (position==0)return 2 ;else return 1;
            }
        });
        mRecy.setLayoutManager(manan);
        DividerItemDecoration diver = new DividerItemDecoration(this,DividerItemDecoration.VERTICAL);
        diver.setDrawable(ContextCompat.getDrawable(this,R.drawable.student_shape_v));
        DividerItemDecoration diver1 = new DividerItemDecoration(this,DividerItemDecoration.HORIZONTAL);
        diver1.setDrawable(ContextCompat.getDrawable(this,R.drawable.student_shape_h));
        mRecy.addItemDecoration(diver);
        mRecy.addItemDecoration(diver1);
        adapter = new MyAdapter(infos);
        mRecy.setAdapter(adapter);
    }





    class MyAdapter extends RecyclerView.Adapter<MyViewHolder> {
        private List<AnswerInfo> infos;
        public MyAdapter(List<AnswerInfo> infos){
            this.infos = infos;
        }

        @NonNull
        @Override
        public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.student_sign_item_layout,parent,false));
        }

        @Override
        public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
            holder.setLayoutInfo(infos.get(position));
        }

        @Override
        public int getItemCount() {
            return infos.size();
        }
    }

    class MyViewHolder extends BaseViewHolder<AnswerInfo>{

        public MyViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setLayoutInfo(AnswerInfo info) {

        }
    }


}
